// pc http://47.108.153.85:8082/
// admin admin
// let baseURI = "http://cjkl.vaiwan.com"
let baseURI = "http://47.108.153.85:9291"
// let baseURI = "http://192.168.111.178:5000"
let token =
	"eyJhbGciOiJIUzUxMiJ9.eyJqdGkiOiIxIiwic3ViIjoiYWRtaW4iLCJpYXQiOjE2MzUzMjQyODcsImlzcyI6IlNDUk0ifQ.IKl_BGh80pMRH91jvLwsAFokzaRD9TXSVgUK3bf6BLAPHY5m-N-3raH5sw6aSfrFz5wLEbdxUSgXaBsjkoG8vQ"
let tokenKey = "3a89247c-3abf-4ec8-8c99-6f9b7bef6d20"

let http = function(reqBody) {
	let {
		url,
		method,
		data
	} = reqBody;
	let header = {}

	token = uni.getStorageSync("token")
	tokenKey = uni.getStorageSync("tokenKey")

	if (token) {
		header = {
			"Authorization": token,
			"Authorization-key": tokenKey
		}
	}
	return new Promise((resolve, reject) => {
		uni.request({
			method,
			url: baseURI + url,
			data,
			header,
			success: (res) => {
				let result = res.data
				if (result.code == 500) {
					uni.showToast({
						title: result.msg,
						icon: "none",
						duration: 2000
					})
					reject(res)
					return;
				}
				resolve(result)
			},
			fail: (e) => {
				reject(e)
			}
		})
	})
}

export default http;
